/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-09-28
 * Time:23:18
 */

/**
 * 力扣74:搜索二维矩阵
 */

public class searchMatrix {
    //二分查找
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n = matrix[0].length;
        int low = 0, high = m * n - 1;
        while (low <= high) {
            int mid = (high - low) / 2 + low;
            int x = matrix[mid / n][mid % n];
            if (x < target) {
                low = mid + 1;
            } else if (x > target) {
                high = mid - 1;
            } else {
                return true;
            }
        }
        return false;
    }
}
